import java.io.Serializable;


public class Employee implements Comparable<Employee>, Serializable{
	
	private String firstName, surname, address, gender;
	private int id, payLevel;
	private Department department;
	

	public Employee(String firstName, String surname, String address, String gender, int id, int payLevel) throws SystemException {
		this.firstName = firstName;
		this.surname = surname;
		this.address = address;
		this.gender = gender;
		if(id < 10000 || id > 29999){
			throw new SystemException(SystemErrors.EMPLOYEE_INVALID_ID);
		}
		this.id = id;
		this.payLevel = payLevel;
		
		this.department = null;
	}

	public int getId(){
		return id;
	}
	
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getSurname() {
		return surname;
	}

	public void setSurname(String surname) {
		this.surname = surname;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public int getPayLevel() {
		return payLevel;
	}

	public void setPayLevel(int payLevel) {
		this.payLevel = payLevel;
	}
	
	public double getSalary(){
		//Get annual salary based on pay level
		double salary = PayScale.getSalary(payLevel);
		//Increase salary if employee is a head
		if(department.getHead() != null && department.getHead().equals(this)){
			salary += 5000;
		}
		return salary;
	}
	
	public void setDepartment(Department d) throws SystemException{
		this.department = d;
	}
	
	public void leaveDepartment(){
		this.department = null;
	}
	
	public Department getDepartment(){
		return this.department;
	}

	@Override
	public String toString() {
		return firstName+" "+surname;
	}

	@Override
	public int compareTo(Employee e) {
		int result = 0;
		//Compare salary of this employee and the other employee
		if(this.getSalary() < e.getSalary()){
			result = 1;
		}
		else if(this.getSalary() > e.getSalary()){
			result = -1;
		}
		
		return result;
	}
	
	
}
